/*
 ============================================================================
 Page	     : 313-314
 Name        : flc.c
 Date	     : 20210405
 Author      : Hbue 18060333
 Copyright   : Your copyright notice
 Description : 有趣的常量
 ============================================================================
 */

#include <stdio.h>
#define COLS 4
int sum2d(const int array[][COLS], int rows);
int sum(const int array[], int n);

int main(void)
{
	int *pt1 = NULL;
	int (*pt2)[COLS];

	pt1 = (int[2]){ 10, 20};
	pt2 = (int[2][COLS]){ { 1, 2, 3, -9}, { 4, 5, 6, -8 } };

	int total1 = sum(pt1, 2);
	int total2 = sum2d(pt2, 2);
	int total3 = sum((int []){ 4, 4, 4, 5, 5, 5 }, 6);

	printf("total1 = %d\n", total1);
	printf("total2 = %d\n", total2);
	printf("total3 = %d\n", total3);

	return 0;
}

int sum(const int array[], int n)
{
	int total = 0;

	for(int i = 0; i < n; i++)
	{
		total += array[i];
	}

	return total;
}

int sum2d(const int array[][COLS], int rows)
{
	int total = 0;

	for(int r = 0; r < rows; r++)
	{
		for(int c = 0; c < COLS;c++)
		{
			total += array[r][c];
		}
	}

	return total;
}

